package org.qiuqiu.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.qiuqiu.service.impl.PostServiceImpl;
import org.qiuqiu.service.impl.ReplyServiceImpl;
import org.qiuqiu.vo.Post;
import org.qiuqiu.vo.Reply;
import org.qiuqiu.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class PageJumpController {
	@Autowired
	private PostServiceImpl postService;
	@Autowired
	private ReplyServiceImpl replyService;
	
	// 首页
	@RequestMapping(value="/index")
	 public String getAllPost() throws Exception {
		/*List<Post> postArrayList=postService.getPostArrayList();
		model.put("postArrayList", postArrayList);*/
		//return "index";
		return "forward:/post/all";
	}
	
	// 登录页面
	@RequestMapping(value="/login")
	public String login() throws Exception {
		return "login";
	}
	
	// 发帖页面
	@RequestMapping(value="/post")
	public String post(HttpSession session, Model model) throws Exception {
		if(session.getAttribute("user")==null){
			model.addAttribute("msg", "请先登录！");
			return "login";
		}
		return "post";
	}
	
	// 贴子内容页面
	@RequestMapping(value="/content")
	public String content() throws Exception {
		return "content";
	}
	
	// 个人中心
	/*@RequestMapping(value="/personal/person")
	public String personal(HttpSession session,Model m) throws Exception {
		User user=(User) session.getAttribute("user");
		List<Post> postList=postService.findAllPostByUser(user);
		System.out.println("我的帖子是"+postList);
		List<Reply> replyList=replyService.findAllReplyByUser(user);
		System.out.println("我回复的帖子"+replyList);
		m.addAttribute("postList", postList);
		m.addAttribute("replyList", replyList);
		return "/personal/personal";
	}
*/
	@RequestMapping(value="/update")
	public String update() throws Exception {
		return "update";
	}
	@RequestMapping(value="/personal/uploadimg")
	public String uploading() throws Exception {
		return "personal/updloadimg";
	}
	@RequestMapping(value="/register")
	public String register(HttpSession session) throws Exception {
		User user=(User) session.getAttribute("user");
		if(user != null){
			return getAllPost();
		}
		return "register";
	}
	
	@RequestMapping(value="/error")
	public String error() throws Exception {
		return "error";
	}
	// 登录页面
		@RequestMapping(value="/head")
		public String test() throws Exception {
			return "head";
		}
		// 回复页面
				@RequestMapping(value="/rep")
				public String test1() throws Exception {
					return "rep";
				}	
}
